<?php
namespace app\api\model;

use think\Model;
use think\Db;

class Cue extends Model
{   
       
    /**
     * 获取当前球杆的状态信息
     *
     * @param string $cue_number   必填, 球杆的编号
     * @return Boolean
     */
    public function getCueStatusInfo($cue_number){
        return Db::name('cue_status')->where('cue_number',$cue_number)->find();
    }

    /**
     * 添加一条球杆状态记录信息
     *
     * @param string $cue_number   必填, 球杆的编号
     * @return Boolean
     */

    public function addCueStatusInfo($cue_number,$lock_id){
        Db::name('cue_status')->where('lock_id',$lock_id)->update(['lock_id' => 0]);
    	$currentTime = time();
	    return Db::name("cue_status")->insertGetId([
	    	'cue_number'      => $cue_number,
            'lock_id'         => $lock_id,
            'create_time'     => $currentTime,
            'update_time'     => $currentTime
        ]);
    }
    
    /**
     * 将球杆放入锁中
     *
     * @param  string $cue_number   必填, 球杆的编号
     * @param  string $lock_id      必填, 锁的编号
     * @return Boolean
     */
    public function putBackCue($cue_number,$lock_id){
    	$currentTime = time();
        Db::name('cue_status')->where('lock_id',$lock_id)->update(['lock_id' => 0]);
        return DB::name('cue_status')->where('cue_number',$cue_number)->update(['lock_id'     => $lock_id,
                                                                         'update_time' => $currentTime
        	                                                           ]);
    }
    
}